
//
//  HomePlanClassNameCell.m
//  test
//
//  Created by 朱圳 on 2018/2/2.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "HomePlanClassNameCell.h"
#import "HomePlanClassContentCell.h"
#import "NSString+Mobile.h"
static NSString * const cellIdtentifier = @"HomePlanClassContentCell";



@interface HomePlanClassNameCell()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableV;
@property(nonatomic,strong)UILabel *classNamLabel;
@property(nonatomic,strong)UIView *topView , * hLineOne , * hLineTwo , * hLineThree;
@property(nonatomic,strong)NSMutableArray *listArray;

@end

@implementation HomePlanClassNameCell


+ (instancetype)cellWithTableView:(UITableView *)tableView withReuseIdentifier:(NSString *)reuseIdentifier
{
    
    HomePlanClassNameCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    cell.selectionStyle = 0;
    if (cell == nil) {
        cell = [[HomePlanClassNameCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.contentView.backgroundColor = [UIColor clearColor];
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews{
    [self.contentView addSubview:self.topView];
    [self.contentView addSubview:self.hLineOne];
    [self.contentView addSubview: self.classNamLabel];
    [self.contentView addSubview:self.hLineTwo];
    [self.contentView addSubview:self.tableV];
    [self.contentView addSubview:self.hLineThree];
    
}
- (UIView *)topView{
    if (!_topView) {
        _topView = [[UIView alloc]init];
        _topView.backgroundColor = [UIColor darkGrayColor];
    }
    return _topView;
}
- (UIView *)hLineOne{
    if (!_hLineOne) {
        _hLineOne = [[UIView alloc]init];
        _hLineOne.backgroundColor = [UIColor darkGrayColor];
    }
    return _hLineOne;
}
- (UILabel *)classNamLabel{
    if (!_classNamLabel) {
        _classNamLabel = [[UILabel alloc]init];
        _classNamLabel.font = [UIFont systemFontOfSize:15];
        _classNamLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _classNamLabel;
}
- (UIView *)hLineTwo{
    if (!_hLineTwo) {
        _hLineTwo = [[UIView alloc]init];
        _hLineTwo.backgroundColor = [UIColor darkGrayColor];
    }
    return _hLineTwo;
}

- (UIView *)hLineThree{
    if (!_hLineThree) {
        _hLineThree = [[UIView alloc]init];
        _hLineThree.backgroundColor = [UIColor darkGrayColor];
    }
    return _hLineThree;
}
- (UITableView *)tableV{
    if (!_tableV) {
        _tableV = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableV.delegate = self;
        _tableV.dataSource = self;
        _tableV.separatorStyle = 0;
        [_tableV registerClass:[HomePlanClassContentCell class] forCellReuseIdentifier:cellIdtentifier];
    }
    return _tableV;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    PlanModel * model = self.modelFrame.model;
    return model.list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomePlanClassContentCell * cell = [HomePlanClassContentCell cellWithTableView:tableView withReuseIdentifier:cellIdtentifier];
    PlanModel * model = self.modelFrame.model;
    ContentModel * contentModel = model.list[indexPath.row];
    cell.contentModel = contentModel;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    PlanModel * model = self.modelFrame.model;
    ContentModel * contentModel = model.list[indexPath.row];
    double maxWidth = ScreenWidth - 10*2- 1*3 - 40;
    CGFloat hight = [contentModel.content getLabelHeighWithMaxWidth:maxWidth font:19];
    NSLog(@"aaHeight======%lf",hight);
    return hight;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModelFrame:(PlanModelFrame *)modelFrame
{
    _modelFrame = modelFrame;
    PlanModel * model = modelFrame.model;
    self.topView.frame = modelFrame.topLineRect;
    self.hLineOne.frame = modelFrame.hLineOneRect;
    self.classNamLabel.frame = modelFrame.classNamLabelRect;
    self.hLineTwo.frame = modelFrame.hLineTwoRect;
    self.tableV.frame = modelFrame.tableVRect;
    self.hLineThree.frame = modelFrame.hLineThreeRect;
    self.classNamLabel.text = model.coursename;
    [self.tableV reloadData];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
